package com.easy.controller;

import com.easy.bean.Category;
import com.easy.service.CategoryService;
import com.easy.util.Page;
import com.easy.util.Result;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/category")
@CrossOrigin
public class CategoryController {
    @Autowired
    CategoryService categoryService;
    @PostMapping
    public Result add(@RequestBody Category category){
        return Result.success("添加成功",categoryService.add(category));
    }

    @DeleteMapping("{id}")
    public Result delete(@PathVariable("id") Integer id){
        return Result.success("删除成功",categoryService.del(id));
    }

    @PutMapping
    public Result edit(@RequestBody Category category){
        return Result.success("修改信息成功",categoryService.edit(category));
    }

    @GetMapping("list")
    public Result list(Category category){
        return Result.success(categoryService.all(category));
    }
    @GetMapping("{id}")
    public Result select(@PathVariable("id") Integer id){
        return Result.success(categoryService.one(id));
    }
    @GetMapping("page")
    public Result page(Page page, Category category){
        categoryService.page(page,category);
        return Result.success(page);
    }



}
